package com.kehongborui.fliggy.mapper;

import com.kehongborui.fliggy.entity.Vehicle;
import com.kehongborui.fliggy.model.QueryVehicleModel;
import com.kehongborui.fliggy.model.VehicleModel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface VehicleMapper {
//    查询余票（查询剩余座位数量）
    Integer getSeatsAmount(String vehicleNo);
    /**
     * 根据 列车编号查找列车信息
     * @param vehicleNo
     * @return
     */
    Vehicle findByVehicleNo(String vehicleNo);

    List<Vehicle> findByDepArrStationAndDate(QueryVehicleModel queryVehicleModel);
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table khbr_vehicle
     *
     * @mbggenerated
     */
    @Delete({
        "delete from khbr_vehicle",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table khbr_vehicle
     *
     * @mbggenerated
     */
    @Insert({
        "insert into khbr_vehicle (id, category, ",
        "vehicle_no, company, ",
        "dep_station, dep_time, ",
        "arr_station, arr_time, ",
        "mileage, seats_amount, ",
        "create_time, update_time, ",
        "dep_date, vehicle_status)",
        "values (#{id,jdbcType=BIGINT}, #{category,jdbcType=TINYINT}, ",
        "#{vehicleNo,jdbcType=VARCHAR}, #{company,jdbcType=VARCHAR}, ",
        "#{depStation,jdbcType=BIGINT}, #{depTime,jdbcType=VARCHAR}, ",
        "#{arrStation,jdbcType=BIGINT}, #{arrTime,jdbcType=VARCHAR}, ",
        "#{mileage,jdbcType=DOUBLE}, #{seatsAmount,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{depDate,jdbcType=DATE}, #{vehicleStatus,jdbcType=TINYINT})"
    })
    int insert(Vehicle record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table khbr_vehicle
     *
     * @mbggenerated
     */
    int insertSelective(Vehicle record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table khbr_vehicle
     *
     * @mbggenerated
     */
    @Select({
        "select",
        "id, category, vehicle_no, company, dep_station, dep_time, arr_station, arr_time, ",
        "mileage, seats_amount, create_time, update_time, dep_date, vehicle_status",
        "from khbr_vehicle",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    Vehicle selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table khbr_vehicle
     *
     * @mbggenerated
     */
    int updateByPrimaryKeySelective(Vehicle record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table khbr_vehicle
     *
     * @mbggenerated
     */
    @Update({
        "update khbr_vehicle",
        "set category = #{category,jdbcType=TINYINT},",
          "vehicle_no = #{vehicleNo,jdbcType=VARCHAR},",
          "company = #{company,jdbcType=VARCHAR},",
          "dep_station = #{depStation,jdbcType=BIGINT},",
          "dep_time = #{depTime,jdbcType=VARCHAR},",
          "arr_station = #{arrStation,jdbcType=BIGINT},",
          "arr_time = #{arrTime,jdbcType=VARCHAR},",
          "mileage = #{mileage,jdbcType=DOUBLE},",
          "seats_amount = #{seatsAmount,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "dep_date = #{depDate,jdbcType=DATE},",
          "vehicle_status = #{vehicleStatus,jdbcType=TINYINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Vehicle record);
}